package com.ruoyi.fit.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fit.domain.HealthExercise;
import com.ruoyi.fit.service.IHealthExerciseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 运动健身数据Controller
 * 
 * @author useragent-1
 * @date 2025-05-16
 */
@Controller
@RequestMapping("/fit/exercise")
public class HealthExerciseController extends BaseController
{
    private String prefix = "fit/exercise";

    @Autowired
    private IHealthExerciseService healthExerciseService;

    @RequiresPermissions("fit:exercise:view")
    @GetMapping()
    public String exercise()
    {
        return prefix + "/exercise";
    }

    /**
     * 查询运动健身数据列表
     */
    @RequiresPermissions("fit:exercise:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HealthExercise healthExercise)
    {
        startPage();
        List<HealthExercise> list = healthExerciseService.selectHealthExerciseList(healthExercise);
        return getDataTable(list);
    }

    /**
     * 导出运动健身数据列表
     */
    @RequiresPermissions("fit:exercise:export")
    @Log(title = "运动健身数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HealthExercise healthExercise)
    {
        List<HealthExercise> list = healthExerciseService.selectHealthExerciseList(healthExercise);
        ExcelUtil<HealthExercise> util = new ExcelUtil<HealthExercise>(HealthExercise.class);
        return util.exportExcel(list, "运动健身数据数据");
    }

    /**
     * 新增运动健身数据
     */
    @RequiresPermissions("fit:exercise:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存运动健身数据
     */
    @RequiresPermissions("fit:exercise:add")
    @Log(title = "运动健身数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HealthExercise healthExercise)
    {
        return toAjax(healthExerciseService.insertHealthExercise(healthExercise));
    }

    /**
     * 修改运动健身数据
     */
    @RequiresPermissions("fit:exercise:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        HealthExercise healthExercise = healthExerciseService.selectHealthExerciseById(id);
        mmap.put("healthExercise", healthExercise);
        return prefix + "/edit";
    }

    /**
     * 修改保存运动健身数据
     */
    @RequiresPermissions("fit:exercise:edit")
    @Log(title = "运动健身数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HealthExercise healthExercise)
    {
        return toAjax(healthExerciseService.updateHealthExercise(healthExercise));
    }

    /**
     * 删除运动健身数据
     */
    @RequiresPermissions("fit:exercise:remove")
    @Log(title = "运动健身数据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(healthExerciseService.deleteHealthExerciseByIds(ids));
    }
}
